package com.custom.headerpagerview;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ViewPager viewPager;
    private MyPagerViewAdapter myPagerViewAdapter;
    private View view1;
    private View view2;
    private View view3;
    private List<View> views;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//版本判断
            // Translucent status bar
            this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//设置statusbar应用所占的屏幕扩大到全屏，但是最顶上会有背景透明的状态栏，它的文字可能会盖着你的应用的标题栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        viewPager = findViewById(R.id.vp_main_show);
        init();
    }

    private void init() {
        views = new ArrayList<>();
        view1 = LayoutInflater.from(this).inflate(R.layout.view1, null);
        view2 = LayoutInflater.from(this).inflate(R.layout.view2, null);
        view3 = LayoutInflater.from(this).inflate(R.layout.view3, null);
        views.add(view1);
        views.add(view2);
        views.add(view3);
        myPagerViewAdapter = new MyPagerViewAdapter(views, MainActivity.this);
        viewPager.setAdapter(myPagerViewAdapter);
    }
}
